//package com.ants.platform.core.plugins.weixin;
//
//import com.ants.platform.core.utils.StringEncryptUtil;
//import com.mongodb.util.JSON;
//import org.xml.sax.InputSource;
//import javax.net.ssl.HttpsURLConnection;
//import java.io.*;
//import java.math.BigDecimal;
//import java.net.MalformedURLException;
//import java.net.ProtocolException;
//import java.net.URL;
//import java.security.KeyManagementException;
//import java.security.NoSuchAlgorithmException;
//import java.security.NoSuchProviderException;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Scanner;
//import java.util.UUID;
//
//
///**
// * Created by liushun on 2016/7/25.
// */
//public class WeiXinPay {
//
//    public static void main(String[] args) {
//        WeiXinPay wx = new WeiXinPay();
//        try {
//            StringBuffer xmlData = wx.httpsRequest("https://api.mch.weixin.qq.com/pay/unifiedorder", "POST", wx.xml());
//            System.out.println(xmlData.toString());
////            Map map = wx.xml2JSON(xmlData.toString());
////            System.out.println("微信返回："+map.get("sign"));
////            Map data = new HashMap();
////            data.put("appId", Const.WEIXINPUBLIC_PAY_APPID);
////            data.put("timeStamp", Long.toString(System.currentTimeMillis() / 1000));
////            data.put("nonceStr", UUID.randomUUID().toString().replaceAll("-", ""));
////            data.put("signType", "MD5");
////            data.put("package", "prepay_id=" + map.get("prepay_id"));
////            String str = "appId="+data.get("appId")+"&timeStamp="+data.get("timeStamp")+"&nonceStr="+
////                    data.get("nonceStr")+"&signType="+data.get("signType")+"&package="+data.get("package")+"&key=" + Const.WEIXINPUBLIC_PAY_APIKEY;
////            System.out.println("字符串："+str);
////            String paySign = StringEncryptUtil.MD5(str).toUpperCase();
////            System.out.println("后台处理："+paySign);
////            data.put("paySign", paySign);
//
//
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//        } catch (NoSuchProviderException e) {
//            e.printStackTrace();
//        } catch (KeyManagementException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
////        Process process = null;
////        try {
////            process = Runtime.getRuntime().exec(new String[] { "wmic", "cpu", "get", "ProcessorId" });
////            process.getOutputStream().close();
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////        Scanner sc = new Scanner(process.getInputStream());
////        String property = sc.next();
////        String serial = sc.next();
////        System.out.println(property + ": " + serial);
//    }
//
//    public String xml() {
//
//        StringBuffer sb = new StringBuffer();
//        String appid = "appid=" + Const.WEIXINPUBLIC_PAY_APPID;
//        String body = "&body=" + Const.WEIXIN_PAY_BODY;
//        String mch_id = "&mch_id=" + Const.WEIXINPUBLIC_PAY_MCHID;
//        String nonce_strId = UUID.randomUUID().toString().replaceAll("-", "");
//        String nonce_str = "&nonce_str=" + nonce_strId;
//        String notify_url = "&notify_url=" + Const.WEIXIN_PAY_NOTIFYURL;
//        String out_trade_no = "&out_trade_no=20160419335863762179";
//        String spbill_create_ip = "&spbill_create_ip=127.0.0.1";
//        String total_feeStr = new BigDecimal("1").setScale(0, BigDecimal.ROUND_HALF_UP).toString();
//        String total_fee = "&total_fee=" + total_feeStr;
//        //String total_fee = "&total_fee=" + pd.getString("TotalPrice");
//        String openidStr = "oYZJcwJrBo4F0BivJFWgEXFlB5FU";
//        String openid = "&openid=" + openidStr;
//        String trade_type = "&trade_type=" + Const.WEIXINPUBLIC_PAY_TRADETYPE;
//        String attach = "&attach=" + Const.WEIXIN_PAY_ATTACH;
//        //一定要按首字母排序
//        String stringA = appid + body + mch_id + nonce_str + notify_url + openid + out_trade_no + spbill_create_ip + total_fee + trade_type;
//        String stringSignTemp = stringA + "&key=" + Const.WEIXINPUBLIC_PAY_APIKEY;
//        //System.out.println(stringSignTemp);
//        //stringSignTemp = "appid=wx9bf169acb95ed5ab&body=订单支付&mch_id=1299337101&nonce_str=b45c993564dc4868a359e187df821d49&notify_url=http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php&out_trade_no=20151216440702126862&spbill_create_ip=127.0.0.1&total_fee=1&trade_type=APP&key=b777b47cbc6511e593ec00163e060757";
//        String sign = StringEncryptUtil.MD5(stringSignTemp).toUpperCase();
//        System.out.println("第一个阿："+sign);
//        //System.out.println(MD5.md5("appid=wx9bf169acb95ed5ab&body=订单支付&mch_id=1299337101&nonce_str=b45c993564dc4868a359e187df821d49&notify_url=http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php&out_trade_no=20151216440702126862&spbill_create_ip=127.0.0.1&total_fee=1&trade_type=APP&key=b777b47cbc6511e593ec00163e060757").toUpperCase());
//        sb.append("<xml>");
//        sb.append("<appid>" + Const.WEIXINPUBLIC_PAY_APPID + "</appid>");
//        sb.append("<body>" + Const.WEIXIN_PAY_BODY + "</body>");
//        sb.append("<mch_id>" + Const.WEIXINPUBLIC_PAY_MCHID + "</mch_id>");
//        sb.append("<nonce_str>" + nonce_strId + "</nonce_str>");
//        sb.append("<notify_url>" + Const.WEIXIN_PAY_NOTIFYURL + "</notify_url>");
//        sb.append("<openid>" + openidStr + "</openid>");
//        sb.append("<out_trade_no>20160419335863762179</out_trade_no>");
//        sb.append("<spbill_create_ip>127.0.0.1</spbill_create_ip>");
//        //sb.append("<total_fee>" + pd.getString("TotalPrice") + "</total_fee>");
//        sb.append("<total_fee>" + total_feeStr + "</total_fee>");
//        sb.append("<trade_type>" + Const.WEIXINPUBLIC_PAY_TRADETYPE + "</trade_type>");
//        sb.append("<sign>" + sign + "</sign>");
//        sb.append("</xml>");
//
//        return sb.toString();
//    }
//
////    public Map xml2JSON(String xml){
////        String str = new XMLSerializer().read(xml).toString();
////        Map map = (Map)JSON.parse(str);
////        return map;
////    }
//
//    private StringBuffer httpsRequest(String requestUrl, String requestMethod, String output)
//            throws NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException, MalformedURLException,
//            IOException, ProtocolException, UnsupportedEncodingException {
//        URL url = new URL(requestUrl);
//        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
//        //HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//        connection.setDoOutput(true);
//        connection.setDoInput(true);
//        connection.setUseCaches(false);
//        connection.setRequestMethod(requestMethod);
//        if (null != output) {
//            OutputStream outputStream = connection.getOutputStream();
//            outputStream.write(output.getBytes("UTF-8"));
//            outputStream.close();
//        }
//        // 从输入流读取返回内容
//        InputStream inputStream = connection.getInputStream();
//        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
//        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//        String str = null;
//        StringBuffer buffer = new StringBuffer();
//        while ((str = bufferedReader.readLine()) != null) {
//            buffer.append(str);
//        }
//        bufferedReader.close();
//        inputStreamReader.close();
//        inputStream.close();
//        inputStream = null;
//        connection.disconnect();
//        return buffer;
//    }
//}
